package Collection.Map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * map
 */
public class Map {
    public static void main(String[] args) {
        HashMap<String,Integer> map = new HashMap<String, Integer>();
        map.put("rose",75);
        map.put("john",85);
        map.put("jack",90);
        map.put("jackson",80);
        map.put("kendaller",100);
        map.put(null,null);

        ConcurrentHashMap a;

        /**
         * map 遍历的5种方式
         */
        System.out.println("-------1、entrySet遍历---------");
        Set<java.util.Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(java.util.Map.Entry<String,Integer> entry : entrySet){
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println("key=" +key +"\t value=" + value );
        }



        System.out.println("\n");
        System.out.println("------ 2、for循环 : keySet()获取key ,values()获取value-----------");
        for(String key : map.keySet()){
            System.out.println("key="+ key + "\t");
        }
        for(Integer value: map.values()){
            System.out.println("value="+value);
        }


        System.out.println("\n");
        System.out.println("------ 3、Iterator 迭代器  :  map.entryset().iterator-----------");
        Iterator<java.util.Map.Entry<String,Integer>> iterator = map.entrySet().iterator();
        while(iterator.hasNext()){
            java.util.Map.Entry<String,Integer> entry = iterator.next();
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println("key=" + key +"\t" + "value=" + value);
        }


        System.out.println("\n");
        System.out.println("------ 4、keySet() value值通过 遍历获取key来get(value)-----------");
        for(String key : map.keySet()){
            Integer value = map.get(key);
            System.out.println("key=" +key +"\t"+ "value=" +value);
        }

        System.out.println("\n");
        System.out.println("------ 5、lambda表达式:forEach--------");
        map.forEach((k,v) -> System.out.println("key=" + k +"\t" +"value="+v));
        
        ConcurrentHashMap<String, String> concurrentHashMap = new ConcurrentHashMap<String,String>();

    }
}
